﻿@{
    Layout = null;
}
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>车间管理</title>
    <link href="//unpkg.com/layui@2.9.17/dist/css/layui.css" rel="stylesheet">
</head>
<body>
    <form class="layui-form layui-row">
        <div class="layui-col-md4">
            <div class="layui-input-wrap">
                <label class="layui-form-label">车间名称：</label>
                <input type="text" style="width:180px" id="workshopname" value="" placeholder="请输入车间名称" class="layui-input" lay-affix="clear">
            </div>
        </div>
        <div class="layui-col-md4">
            <div class="layui-input-wrap">
                <label class="layui-form-label">车间编码：</label>
                <input type="text" style="width:180px" id="workshopcode" value="" placeholder="请输入车间编码" class="layui-input" lay-affix="clear">
            </div>
        </div>
        <div class="layui-btn-container ">
            <button class="layui-btn" lay-submit lay-filter="demo-table-search">查询</button>
            <button type="reset" class="layui-btn layui-btn-primary">清空</button>
            <button type="button" class="layui-btn layui-btn-primary layui-bg-blue"  id="addData"> 添加</button>
        </div>
    </form>
    <table class="layui-hide" id="test"></table>
    <script src="~/Scripts/jquery-3.4.1.min.js"></script>
    <script src="//unpkg.com/layui@2.9.17/dist/layui.js"></script>
    <script>
        layui.use(function () {
            var table = layui.table;
            var layer = layui.layer;
            var form = layui.form;
            var table = layui.table;
            var util = layui.util;
            //显示
            function show() {
                table.render({
                    elem: '#test',
                    url: '/Song/GetMdWorkshopList',  
                    //maxHeight: '530px',
                    //toolbar: '#TPL-treeTable-demo',
                     page: true, //开启分页
                     limit: 10,
                     limits: [10, 20, 50, 100],
                    cols: [[
                        { field: 'workshopCode', title: '车间编码', width: 200, fixed: 'left' },
                        { field: 'workshopName', title: '车间名称', width: 120 },
                        { field: 'area', title: '面积', width: 120 },
                        { field: 'charger', title: '负责人', width: 120 },  
                        {
                            field: 'enableFlag', title: '是否启用', width: 150, templet: function (row) {
                                var tmp = row.enableFlag == 'Y' ? "是" : "否";
                                return tmp;
                            }
                        },
                           { field: 'remark', title: '备注', width: 120 },
                        {
                            fixed: "right", title: "操作", width: 180, align: "center", templet: function (row) {
                                var tmp = '<a class="layui-btn layui-btn-xs layui-bg-blue" lay-event="detail">查看</a>';
                                 tmp += '<a class="layui-btn layui-btn-xs layui-bg-red" lay-event="delChild">删除</a>';
                                return tmp;
                            }
                        }
                    ]],
                });
            }

            show();//初始化显示
            // 搜索提交
            form.on('submit(demo-table-search)', function (data) {
                var name = $("#workshopname").val();    //分类名称
                var code = $("#workshopcode").val();    //是否启用
                // 执行搜索重载
                table.reload('test', {
                    page: {
                        curr: 1 // 重新从第 1 页开始
                    },
                    where: {
                        workshopname: name,
                        workshopcode: code
                    }// 搜索的字段
                });
                return false; // 阻止默认 form 跳转
            });
            
                // 添加分类
                    $("#addData").click(function () {
                      layer.open({
                        type: 2,
                        title: '添加车间',
                         shadeClose: true, // 点击遮罩区域，关闭弹层
                          scrollbar: false, // 暂时屏蔽浏览器滚动条
                        skin: 'layui-layer-rim', //加上边框
                        area: ['620px', '440px'], //宽高
                        content: '/Song/AddMdIWorkshop',
                        end: function () {
                            show();//刷新父级页面列表方法，类似于回调函数
                        }
                    });        
                    });

            // 单元格工具事件
            table.on('tool(test)', function (obj) {
                var layEvent = obj.event; // 获得 lay-event 对应的值
                var trData = obj.data;
                if (layEvent === "detail") {
                    var data = obj.data;//获取表单中的点击按钮的那一行数据
                    workshopCode = data.workshopCode;
                    workshopName = data.workshopName;
                    area = data.area;
                    charger = data.charger;
                    id = data.id;
                    enableFlag = data.enableFlag;
                    remark = data.remark;
                    createTime = data.createTime;
                    createBy = data.createBy;
                    layer.open({
                        title: '修改车间信息',
                        skin: 'layui-layer-rim', //加上边框
                        type: 2,
                         shadeClose: true, // 点击遮罩区域，关闭弹层
                          scrollbar: false, // 暂时屏蔽浏览器滚动条
                        area: ['620px', '440px'],
                        content: '/Song/UpdMdIWorkshop',
                        end: function () {
                            show();
                        }
                    });
                }  else if (layEvent === "delChild") {
                    layer.confirm("确定要删除吗？", function (data) {
                        var id = { id: trData.id };
                        // 此处可执行 Ajax 等操作
                        $.get('/Song/DeleteMdWorkshop', id, function (res) {
                            if (res) {
                                layer.msg("删除成功", { icon: 1, time: 1000 }, function () {
                                    obj.del();
                                    // 刷新表格
                                    table.reload('test');
                                });
                            } else {
                                layer.msg("删除失败", { icon: 2, time: 1000 });
                            }
                        });
                    });
                }
            });
        });
    </script>
</body>
</html>